package com.google.code.ptrends.Application.DAL;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import com.google.code.ptrends.Application.DAL.entities.CategoryEntity;
import com.google.code.ptrends.Application.DAL.entities.ItemEntity;
import com.google.code.ptrends.Application.DAL.entities.ManufacturerEntity;
import com.google.code.ptrends.Application.DAL.entities.SupplierEntity;

/**
 * Session Bean implementation class SearchServiceBean
 */
@Stateless
@LocalBean
public class SearchServiceBean {

	@PersistenceContext(name = "Application.DAL")
	private EntityManager entityManager;
	
    public SearchServiceBean() {
        // TODO Auto-generated constructor stub
    }
    
    public List<ManufacturerEntity> getAllManufacturer() {
    	TypedQuery<ManufacturerEntity> query = entityManager.createQuery(
    			"select m from ManufacturerEntity m", 
    			ManufacturerEntity.class);
    	return query.getResultList();
    }
    
    public List<SupplierEntity> getAllSupplier() {
    	TypedQuery<SupplierEntity> query = entityManager.createQuery(
    			"select s from SupplierEntity s", 
    			SupplierEntity.class);
    	return query.getResultList();
    }
    
    public List<CategoryEntity> getAllCategory() {
    	TypedQuery<CategoryEntity> query = entityManager.createQuery(
    			"select c from CategoryEntity c", 
    			CategoryEntity.class);
    	return query.getResultList();
    }
    
    public List<ItemEntity> getAllItem() {
    	TypedQuery<ItemEntity> query = entityManager.createQuery(
    			"select i from ItemEntity i", 
    			ItemEntity.class);
    	return query.getResultList();
    }

}
